package com.itheima.controller;

import com.itheima.Service.EmpService;
import com.itheima.entity.LoginInfo;
import com.itheima.entity.Result;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {
    private static final org.slf4j.Logger log = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginInfo loginInfo){
        log.info("用户登录：{}", loginInfo);

        LoginInfo loginInfoDB = empService.login(loginInfo);

        if (loginInfoDB == null) return Result.error("用户名或密码错误");

        return Result.success(loginInfoDB);
    }
}
